package com.yxkj.syh.app.huarong.activities.item_select;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.syh.app.basic.utils.net.cookie.PersistentCookieStore;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.adps.ItemSelectAdp;
import com.yxkj.syh.app.huarong.bean.BuyerResponse;
import com.yxkj.syh.app.huarong.bean.LinkListResponse;
import com.yxkj.syh.app.huarong.bean.PagesRequest;
import com.yxkj.syh.app.huarong.bean.PaperFactoryResponse;
import com.yxkj.syh.app.huarong.data_center.model.CommonModel;
import com.yxkj.syh.app.huarong.data_center.model.OrderModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建者：SYH
 * 时间：2020/5/21 17:49
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class ItemSelectVM extends BaseViewModel<ActivityEvent> {


    public ItemSelectVM(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Object> mldShowText = new MutableLiveData<>();

    /**
     * 业务员列表
     */
    public void buyerList() {
        OrderModel.getOrderModel().saleManList(mLifecycleProvider.bindToLifecycle(), new ApiObserver<BuyerResponse>() {
            @Override
            public void onSuccess(BuyerResponse buyerResponse) {
                mldShowText.setValue(buyerResponse.getData());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }


    /**
     * 供应商列表
     */
    public void linkList() {
        PagesRequest linksRequest = new PagesRequest();
        linksRequest.setPageIndex(1);
        linksRequest.setPageSize(1000);
        linksRequest.setQueryList(new ArrayList<>());
        linksRequest.setSortFields("o.createTime_d");
        CommonModel.getCommonModel().linkList(linksRequest, mLifecycleProvider.bindToLifecycle(), new ApiObserver<LinkListResponse>() {
            @Override
            public void onSuccess(LinkListResponse response) {
                mldShowText.setValue(response.getData().getRecords());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

    /**
     * 纸厂列表
     */
    public void factoryList() {
        OrderModel.getOrderModel().paperFactoryList(mLifecycleProvider.bindToLifecycle(), new ApiObserver<PaperFactoryResponse>() {
            @Override
            public void onSuccess(PaperFactoryResponse paperFactoryResponse) {
                mldShowText.setValue(paperFactoryResponse.getData());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

}
